//
//  JZHShare.m
//  极致荟
//
//  Created by hetao on 14-5-13.
//  Copyright (c) 2014年 mac. All rights reserved.
//

#import "JZHShare.h"
#import "JZHPublishActivityViewController.h"
#import <ShareSDK/ShareSDK.h>
@implementation JZHShare
UIViewController * con;
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}
- (IBAction)quxiao:(UIButton *)sender {
    
    
    
        [UIView animateWithDuration:0.3 animations:^{
            [self.shareview1 setFrame:CGRectMake(0, self.frame.size.height, self.shareview1.frame.size.width, self.shareview1.frame.size.height)];
            [self.shareview2 setFrame:CGRectMake(0, self.frame.size.height, self.shareview2.frame.size.width, self.shareview2.frame.size.height)];

        } completion:^(BOOL finished) {
            [self removeFromSuperview];
        }];

    
    
    
    
    
}
- (void)show:(int)index viewcontroller:(UIViewController *)contcroller
{
    con=contcroller;
    if(index==1)
    {
        self.shareview1.hidden=NO;
        self.shareview2.hidden=YES;
        [self.quxiaobut.layer setCornerRadius:6.0];
        [self.shareview1 setFrame:CGRectMake(0, con.view.frame.size.height, self.shareview1.frame.size.width, self.shareview1.frame.size.height)];
        [[UIApplication sharedApplication].windows[0] addSubview:self];
        
        [UIView animateWithDuration:0.3 animations:^{
            if([UIDevice currentDevice].systemVersion.floatValue > 6.5)
            {
                [self.shareview1 setFrame:CGRectMake(0,
                                                     con.view.frame.size.height- self.shareview1.frame.size.height,
                                                     self.shareview1.frame.size.width,
                                                     self.shareview1.frame.size.height)];
            }
            else
            {
                [self.shareview1 setFrame:CGRectMake(0,
                                                     con.view.frame.size.height- self.shareview1.frame.size.height + 64,
                                                     self.shareview1.frame.size.width,
                                                     self.shareview1.frame.size.height + 20)];
            }
        }];

    }else
    {
        self.shareview1.hidden=YES;
        self.shareview2.hidden=NO;
        [self.quxiaobut2.layer setCornerRadius:6.0];
        [self.shareview2 setFrame:CGRectMake(0,  con.view.frame.size.height, self.shareview2.frame.size.width, self.shareview2.frame.size.height)];
        [[UIApplication sharedApplication].windows[0] addSubview:self];
        
        [UIView animateWithDuration:0.3 animations:^{
            if([UIDevice currentDevice].systemVersion.floatValue > 6.5)
            {
                [self.shareview2 setFrame:CGRectMake(0,
                                                     con.view.frame.size.height- self.shareview2.frame.size.height,
                                                     self.shareview2.frame.size.width,
                                                     self.shareview2.frame.size.height)];
            }
            else
            {
                [self.shareview2 setFrame:CGRectMake(0,
                                                     con.view.frame.size.height- self.shareview2.frame.size.height + 64,
                                                     self.shareview2.frame.size.width,
                                                     self.shareview2.frame.size.height + 20)];
            }
        }];

    }
    
}
- (IBAction)pushuodong:(id)sender {
   
    
}

//品鉴
- (IBAction)puspingjian:(UIButton *)sender
{
    [self quxiao:nil];
    [UINavigationController Pus:con ToViewconeroller:[[JZHPublishActivityViewController alloc]inittype:sender.tag-300] ];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

///分享到新浪微博
- (IBAction)sinashare:(UIButton *)sender
{
    [self share:1];
}
//易信好友
- (IBAction)yixin:(id)sender {
    [self share:38];
}
//易信朋友圈
- (IBAction)yixinss:(id)sender {
     [self share:39];
}
//微信朋友圈
- (IBAction)weixpengyouquan:(id)sender {
    [self share:23];
}
//微信
- (IBAction)weixn:(id)sender {
    [self share:22];
}
//刷新
- (IBAction)sefrl:(id)sender {
    self.refresh();
}
//设置分享数据
- (void)shareData:(NSString *)title shareTxt:(NSString* )txt image:(NSData *)image
{
    self.imagepath=image;
    self.title=title;
    self.shareTxt=txt;
}
///分享数据
- (void)share:(int)type
{
    [self quxiao:nil];
    id<ISSCAttachment> catt=[ShareSDK imageWithData:self.imagepath fileName:@"" mimeType:@""];
    id<ISSContent> iss=[ShareSDK content:self.shareTxt defaultContent:self.shareTxt image:nil title:self.title url:@"http://www.sharesdk.cn" description:self.shareTxt mediaType:SSPublishContentMediaTypeText locationCoordinate:nil];

    if(type !=22 && type!=23)
    {
        [ShareSDK shareContent:iss type:type authOptions:nil shareOptions:nil statusBarTips:YES result:^(ShareType type, SSResponseState state, id<ISSPlatformShareInfo> statusInfo, id<ICMErrorInfo> error, BOOL end) {
            NSLog(@"%@",error.errorDescription);
        }];

    }else
    {
        [ShareSDK shareContent:iss type:ShareTypeWeixiSession authOptions:nil shareOptions:nil statusBarTips:YES result:^(ShareType type, SSResponseState state, id<ISSPlatformShareInfo> statusInfo, id<ICMErrorInfo> error, BOOL end) {
            NSLog(@"mmm%d %@  %d",[error errorCode],[error errorDescription],[error errorLevel]);
        }];
       
    }
    
   
   
}
@end
